//
//  WXMainViewController.swift
//  weibo
//
//  Created by 王旭 on 16/4/16.
//  Copyright © 2016年 王旭. All rights reserved.
//

//1.WXMainViewController -> WXTabBar
//2.WXTabBar -> addButtonClosure
//3.

import UIKit

class WXMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //加好按钮闭包
        let addButtonClosure = { ()->() in
            
//            print("需要跳转控制器")
            //创建弹出的view
            let composeView = WXComposeView()
            composeView.show(self)
//            //添加到tabBarController的view上
//            self.view.addSubview(composeView)
            

        }
        
        //自定义tabBar
        let tabBar = WXTabBar()
        self.setValue(tabBar, forKey: "tabBar")
        //关联闭包属性
        tabBar.addButtonClosure = addButtonClosure
        //tabBar只读属性,以下赋值方式不可以
//        self.tabBar = tabBar
        
//设置tabBar的外观(图片和文字) --> 全局统一设置--------------------------------
//        let tabBar = UITabBar.appearance()
//        tabBar.tintColor = UIColor.orangeColor()
//设置tabBar的外观(图片和文字) --> 全局统一设置---------------------------------
        
        
//-------创建tabBarController的子控制器--------------------------------------
//        let vc = UITableViewController()
//        let naviVC = UINavigationController(rootViewController: vc)
//        addChildViewController(naviVC)
//-------创建tabBarController的子控制器--------------------------------------
        
        addChildViewController(WXHomeTableViewController(), title: "首页", imgNamed: "tabbar_home")
        addChildViewController(WXMessageTableViewController(), title: "消息", imgNamed: "tabbar_message_center")
        addChildViewController(WXDiscoverTableViewController(), title: "发现", imgNamed: "tabbar_discover")
        addChildViewController(WXProfileTableViewController(), title: "我", imgNamed: "tabbar_profile")
    }
    
    func addChildViewController(childController: UIViewController, title:String, imgNamed:String) {
        
        //设置文字(导航栏和底部子控制器文字)
        childController.title = title
        
//------设置tabBar子控制器的文字和导航栏文字不一样------------------------------
//        childController.tabBarItem.title = "不一样"
//------设置tabBar子控制器的文字和导航栏文字不一样------------------------------
        
        //设置默认和选中状态下的图片
        childController.tabBarItem.image = UIImage(named: imgNamed)
        //图片选中状态默认
//        childController.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")
        //图片选中状态不渲染
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置tabBar文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        ///设置tabBar文字大小
//        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: .Normal)
        //加粗
//        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.boldSystemFontOfSize(14)], forState: .Normal)
        //斜体,有问题?
//        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.italicSystemFontOfSize(20)], forState: .Normal)
        
        //设置tabBar图片位置---文字图片都在图片时的情况
//        childController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
        
        //创建tabBarController的子控制器
        addChildViewController(UINavigationController(rootViewController: childController))
        
    }


}
